
#include <colorpicker/colorpicker.h>
#include <colorpicker/colorselectorbutton.h>
#include <stdio.h>

namespace
{

QString create_color_qss (const QColor& color)
{
  QString colorStr;
  colorStr.sprintf("rgb(%d, %d, %d)", color.red(), color.green(), color.blue());
  QString qss = QString ("      \n"
                         "      \n"
                         "QPushButton {\n"
                         "  border-top-left-radius: 6px;\n"
                         "  border-bottom-left-radius: 6px;\n"
                         "  border-top-right-radius: 6px;\n"
                         "  border-bottom-right-radius: 6px;\n"
                         "  border: 2px solid #000000;\n"
                         "  background-color: %1;\n"
                         "}\n"

                         "QPushButton:hover {\n"
                         "  border-top-left-radius: 6px;\n"
                         "  border-bottom-left-radius: 6px;\n"
                         "  border-top-right-radius: 6px;\n"
                         "  border-bottom-right-radius: 6px;\n"
                         "  border: 3px solid #a0a0a0;\n"
                         "  background-color: %1;\n"
                         "}\n"

                         "").arg (colorStr);
  printf ("ColorQSS: %s\n", (const char*)qss.toAscii());
  fflush(stdout);
  return qss;
}

}

cceColorSelectorButton::cceColorSelectorButton(QWidget *parent)
  : QPushButton(parent)
{
  SetColor(QColor (255, 255, 255, 255));
  connect (this, SIGNAL(clicked()), SLOT(ChangeColor()));
}

void cceColorSelectorButton::ChangeColor()
{
  SetColor (cceColorPickerDialog::GetColor(0, _color, "Select color"));
}

void cceColorSelectorButton::SetColor(const QColor &color)
{
  _color = color;
  setStyleSheet(create_color_qss (_color));
}

const QColor& cceColorSelectorButton::GetColor () const
{
  return _color;
}


